/**
 * 
 */
requirejs.config({
    baseUrl:'http://static.auoffice.com/static/js' ,
    waitSeconds: 0,
    paths: {
    	jquery:'libs/jquery.min',
    	validate:'libs/validate/jquery.validate.min',
        chosen:'libs/chosen/chosen.jquery',
        //plugins
        base: 'common/base',
    },
    shim: {
    	'validate': {
    		deps: ['jquery'],
    		exports: 'validate'
    	},
        'chosen': {
            deps: ['jquery'],
            exports: 'chosen'
        },
    }
});

require([
    'jquery',
 	'common/base',
 	'chosen',
 	'validate',
],function($,base,chosen) {
	$(document).ready(function(){
		$(".designee-select").chosen({no_results_text: "没有匹配结果"});
		$(".chosen-container .chosen-drop .chosen-results").css("max-height","150px");
	})
	//validate全局设置
	$.validator.setDefaults({ 
		ignore: ":hidden:not(select)",
		errorPlacement: function(error, element) {
			element.parent().append(error);
		} 
	});
	//下拉框改变事件
    $('select').bind("change", function(){
    	$("#Form").validate().element($(this));
    });
	//表单验证
	$("#Form").validate({
		rules:{
			title:{//标题
				required:true,
				maxlength:64,
			},
			designee_id:{//指派给
				required:true,
			},
			content:{//内容
				required:true,
			},
		},
		messages:{
			title:{
				required:"请输入标题",
				maxlength:"标题最大长度为64个字符"
			},
			designee_id:{//指派给
				required:"请选择指派的人",
			},
			content:{//内容
				required:"请输入需求内容",
			},
		},
		submitHandler:function(){
			base.services.post('demand', 'saveDemand', $("#Form").serialize(), function(code, msg, data) {
				if (code === base.services.CODE_SUCC) {
					base.layui.alert("成功信息","保存成功");
				} else {
					base.layui.alert("错误信息",msg);
				}
			});
		}
	});
});